﻿#ifndef IMAGEITEM_H
#define IMAGEITEM_H

#include <QSharedPointer>
#include <QVariant>
#include <QSize>
#include <QImage>
#include <QObject>

enum ColomName {
    CN_IMAGE = 1,
    CN_INFO,
    CN_PATH
};

class ImageItem : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString file READ file WRITE setFile NOTIFY fileChanged)
    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
    Q_PROPERTY(QString info READ info WRITE setInfo NOTIFY infoChanged)
    Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged)
    Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged)

    //饱和度、亮度、对比度
    Q_PROPERTY(int staturate READ staturate WRITE setStaturate NOTIFY staturateChanged)
    Q_PROPERTY(int bright READ bright WRITE setBright NOTIFY brightChanged)
    Q_PROPERTY(int contrast READ contrast WRITE setContrast NOTIFY contrastChanged)

public:
    explicit ImageItem(QObject *parent = nullptr);

    QVariant data(int col);

    bool setData(int col,QVariant value);

    QString file() const
    {
        return m_file;
    }

    QString info() const
    {
        return m_info;
    }

    QSize size() const
    {
        return m_size;
    }

    QImage image() const
    {
        return m_image;
    }

    QString name() const
    {
        return m_name;
    }

    int staturate() const
    {
        return m_staturate;
    }

    int bright() const
    {
        return m_bright;
    }

    int contrast() const
    {
        return m_contrast;
    }

public slots:
    void setFile(QString file)
    {
        if (m_file == file)
            return;

        m_file = file;
        emit fileChanged(m_file);
        emit dataChanged();
    }

    void setInfo(QString info)
    {
        if (m_info == info)
            return;

        m_info = info;
        emit infoChanged(m_info);
        emit dataChanged();
    }

    void setSize(QSize size)
    {
        if (m_size == size)
            return;

        m_size = size;
        emit sizeChanged(m_size);
        emit dataChanged();
    }

    void setImage(QImage image)
    {
        if (m_image == image)
            return;

        m_image = image;
        emit imageChanged(m_image);
    }

    void setName(QString name)
    {
        if (m_name == name)
            return;

        m_name = name;
        emit nameChanged(m_name);
    }

    void setStaturate(int staturate)
    {
        if (m_staturate == staturate)
            return;

        m_staturate = staturate;
        emit staturateChanged(m_staturate);
    }

    void setBright(int bright)
    {
        if (m_bright == bright)
            return;

        m_bright = bright;
        emit brightChanged(m_bright);
    }

    void setContrast(int contrast)
    {
        if (m_contrast == contrast)
            return;

        m_contrast = contrast;
        emit contrastChanged(m_contrast);
    }

signals:
    void fileChanged(QString file);

    void infoChanged(QString info);

    void sizeChanged(QSize size);

    void dataChanged();

    void imageChanged(QImage image);

    void nameChanged(QString name);

    void staturateChanged(int staturate);

    void brightChanged(int bright);

    void contrastChanged(int contrast);

private:
    QString m_file;
    QString m_info;
    QSize m_size;
    QImage m_image;
    QString m_name;
    int m_staturate = 0;
    int m_bright = 0;
    int m_contrast = 0;
};

typedef QSharedPointer<ImageItem> ImageItemPtr;

#endif // IMAGEITEM_H
